/*
 * @Author: 张小平
 * @Date:   2025-05-01 
 * @Email:  qqshuqian@163.com 
 * @Copyright © 2024 aseyun. All rights reserved.
 */

import compression from 'vite-plugin-compression'

export default function createCompression (env) {
  const { VITE_BUILD_COMPRESS } = env
  const plugin = []
  if (VITE_BUILD_COMPRESS) {
    const compressList = VITE_BUILD_COMPRESS.split(',')
    if (compressList.includes('gzip')) {
      plugin.push(
        compression({
          ext: '.gz',
            verbose: true,
            disable: false,
            threshold: 10240,// 10k
            deleteOriginFile: false //浏览器在支持gzip压缩的情况下，会自动加载gzip压缩过的文件而不是源文件，所以为了项目的正常运行我们一般将deleteOriginFile设为false，即不删除源文件。为了看压缩效果可以设置成truea

    })
      )
    }
    if (compressList.includes('brotli')) {
      plugin.push(
        compression({
          ext: '.br',
          algorithm: 'brotliCompress',
          deleteOriginFile: false
        })
      )
    }
  }
  return plugin
}
